﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace WG计划管理工具
{
    public static class clsTools
    {
        public static double GetDouble(object tmpobj)
        {
            double r = 0d;
            try
            {
                r = Convert.ToDouble(tmpobj);
            }
            catch
            {
                r = 0d;
            }
            return r;
        }

        public static int GetInt(object tmpobj)
        {
            int r = 0;
            try
            {
                r = Convert.ToInt32(tmpobj);
            }
            catch
            {
                r = 0;
            }
            return r;
        }

        public static string GetString(object tmpobj)
        {
            try
            {
                return tmpobj.ToString();
            }
            catch
            {
                return string.Empty;
            }
        }

        public static bool GetBoolean(object tmpobj)
        {
            try
            {
                return Convert.ToBoolean(tmpobj);
            }
            catch
            {
                return false;
            }
        }

        public static void ShowWarningMsg(string strTmpMsg)
        {
            MessageBox.Show(strTmpMsg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

        public static void ShowErrMsg(string strTmpMsg)
        {
            MessageBox.Show(strTmpMsg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        public static void ShowInfo(string strTmpMsg)
        {
            MessageBox.Show(strTmpMsg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        public static bool VerifyPermission(string strTmpUserID, string strTmpPermission)
        {
            SqlTools.SqlTools sqt = new SqlTools.SqlTools(WG计划管理工具.Properties.Settings.Default.ConnectionString);
            string strTmpCheckPermission = "select 序号 from wgqx where 用户编号='" + strTmpUserID + "' and 权限='" + strTmpPermission + "'";
            bool bResult=sqt.RecordExist(strTmpCheckPermission);
            if (!bResult )
            {
                ShowWarningMsg("无此权限！");
            }
            return bResult ;
        }
    }
}
